
// Copyright (c) 2009 Mohannad Alharthi (mohannad.harthi@gmail.com)
// All rights reserved.
// This source code is licensed under the BSD license, which can be found in
// the LICENSE.txt file.

#ifndef INLCUDE_CCOMPX_SRC_MISC_H__
#define INLCUDE_CCOMPX_SRC_MISC_H__

#include <string>

// A simple string format function
std::string format(std::string format_str, ...);

// Replaces all occurences of old_value with new_value in source
void findAndReplaceAll(std::string& source,
                       const char* old_value,
                       const char* new_value);

// A location in a source file
class Location {
 public:
  Location() {
  }
  Location(const std::string& file, int line, int column)
    : file_(file), line_(line), column_(column) {
  }

  std::string file() {
    return file_;
  }
  int line() {
    return line_;
  }
  int column() {
    return column_;
  }
  void set_line(int line) {
    line_ = line;
  }
  void set_column(int col) {
    column_ = col;
  }

private:
  std::string file_;
  int line_;
  int column_;
};

// A compiler message associated with a location
class Message {
 public:
  Message(const std::string& message)
    : message_(message) {
  }
  Message(const std::string& message, const Location& loc)
    : message_(message), location_(loc) {
  }

  std::string message() {
    return message_;
  }
  Location location() {
    return location_;
  }

private:
  std::string message_;
  Location location_;
};

#endif // INLCUDE_CCOMPX_SRC_MISC_H__
